import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.globals import ThemeType
df = pd.read_excel('国内生产总值季度数据.xlsx',index_col=0)
df = df.sort_index(axis='columns')
line = Line(init_opts=opts.InitOpts(
    width='1200px',height='600px',
    theme=ThemeType.SHINE,page_title='折线图'))
line.add_xaxis(xaxis_data=df.columns.tolist())
line.add_yaxis(series_name='第一产业',y_axis=df.loc['第一产业增加值（亿元）'])
line.add_yaxis(series_name='第二产业',y_axis=df.loc['第二产业增加值（亿元）'])
line.add_yaxis(series_name='第三产业',y_axis=df.loc['第三产业增加值（亿元）'])

line.set_global_opts(
    title_opts=opts.TitleOpts(
        title='2019-2022年每年各季度第一产业，第二产业，第三产业增加值折线图',
        pos_left='center'),
    yaxis_opts=opts.AxisOpts(name='增产值(亿元)',
        name_location='center',name_gap=55,min_=45000),
    legend_opts=opts.LegendOpts(pos_right='10%',pos_top='5%'))
line.render('例7-1.html')